<?php

namespace app\common\model\shop;

use app\common\model\Area;
use app\common\utils\Utils;
use think\Model;


class Address extends Model
{

    

    // 表名
    protected $name = 'shop_address';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'address_text',
    ];



    public function getStatusList()
    {
        return ['0' => '否', '1' => '是'];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_default']) ? $data['is_default'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAddressTextAttr($value, $data)
    {
        $province = $data['province'];
        $city = $data['city'];
        $area = $data['area'];
        $address = $data['detail'];

        $arr = [$province, $city, $area];
        $values = Area::where(['id' => ['in', $arr]])->order('id asc')->column('name', 'id');

        $str = Utils::implodeArr($values, '');

        return $str . '' . $address;
    }




}
